package com.test;

import org.apache.poi.xwpf.usermodel.*;

import java.io.FileInputStream;
import java.io.IOException;

public class WordStyleParser {

    public static void main(String[] args) {
        try (FileInputStream fis = new FileInputStream("D:/WorkPlace/毕设选题线上小程序/words/翁学森任务书.docx");
             XWPFDocument document = new XWPFDocument(fis)) {

//            for (XWPFParagraph paragraph : document.getParagraphs()) {
//                for (XWPFRun run : paragraph.getRuns()) {
//                    System.out.println("Text: " + run.getText(0));
////                    System.out.println("Alignment: " + run.getAlignment());
////                    System.out.println("Font Size: " + paragraph.getFontAlignment());
//                System.out.println("Font Family: " + run.getFontFamily());
//                System.out.println("Color: " + run.getColor());
//                System.out.println("FontSize: " + run.getFontSize());
////                    System.out.println("Indentation: " + paragraph.getIndentationFirstLine());
////                    System.out.println("Spacing: " + paragraph.getSpacingBefore());
//                    System.out.println("--------------------------------------------------");
//                }
            for (XWPFTable table : document.getTables()) {
                for (XWPFTableRow row : table.getRows()) {
                    for (XWPFTableCell cell : row.getTableCells()) {
                        for (XWPFParagraph paragraph : cell.getParagraphs()) {
                            for (XWPFRun run : paragraph.getRuns()) {
                                System.out.println("表格内容： " + run.getText(0));
//                                text.put("表格"+j+"内容：",run.getText(0));
                                System.out.println("字体： " + run.getFontFamily());
//                                text.put("表格"+j+"字体：",run.getFontFamily());
                                System.out.println("字号： " + run.getFontSize());
//                                text.put("表格"+j+"字号：",run.getFontSize());
                            }
                        }
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
